package com.woniuxy.company5.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.company5.dto.LRepNewDto;

import com.woniuxy.company5.entity.RepNew;
import com.woniuxy.company5.service.RepNewService;
import com.woniuxy.company5.util.Result;
import com.woniuxy.company5.vo.LRepNewVo;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/repNew")
public class RepNewController {
    @Resource
    private RepNewService repNewService;
    @PostMapping("query")
    public Result queryByLike(@RequestBody LRepNewDto repNewDto){
        PageHelper.startPage(repNewDto.getCurrentPage(),repNewDto.getPageSize(),true);
        List<LRepNewVo> repNew = repNewService.selectByLike(repNewDto);
        PageInfo<LRepNewVo> pageInfo = new PageInfo<>(repNew);
        return Result.ok().data("userList",repNew).data("total",pageInfo.getTotal());
    }
    @PostMapping("")
    public Result add(@RequestBody RepNew repNew){
        repNew.setNum(new Date().getTime()+"");
        repNew.setDate(new Date());
        repNewService.insertSelective(repNew);
        return Result.ok();
    }
    @GetMapping("{id}")
    public Result queryById(@PathVariable("id") Long id){
        RepNew repNew = repNewService.selectByPrimaryKey(id);
        return Result.ok().data("user",repNew);
    }
    @PutMapping("")
    public Result update(@RequestBody RepNew repNew){
        repNewService.updateByPrimaryKeySelective(repNew);
        return Result.ok();
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id){
        repNewService.deleteByPrimaryKey(id);
        return Result.ok();
    }
}
